home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / CLPARM.CPP < prev    next >
C/C++ Source or Header  |  1993-08-24  |  25KB  |  843 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    clparm.cpp
  5. //   Title:    C++ Class Libraries
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //    This module contains code for the class CL_PARM.
  24. //
  25. //    The code in this module may be written in C++ or C.
  26. //
  27. //    This module is portable to:
  28. //        DOS 3.X+
  29. //        MS Windows 3.X+
  30. //        OS/2 2.X+
  31. //        OS/2 2.0 PM
  32. //
  33. //    The following compilers are supported:
  34. //        MSC 6.0A
  35. //        MSC/C++ 7.0
  36. //        Borland C++ 3.1 for DOS
  37. //        Borland C++ 1.0 for OS/2 2.X
  38. //
  39. //----------------------------------------------------------------------------
  40. #include <class.hpp>
  41.  
  42. //----------------------------------------------------------------------------
  43. // Globals
  44. //----------------------------------------------------------------------------
  45. PCSZ CL_PARM::pcszParmName   = "~PARM";
  46. PCSZ CL_PARM::pcszGarbleName = "~GARBLE";
  47.  
  48. PCSZ CL_PARM::pcszVersion    = "VERSION";
  49. PCSZ CL_PARM::pcszAccess     = "ACCESS_CODE";
  50. PCSZ CL_PARM::pcszSerial     = "SERIAL_NO";
  51. PCSZ CL_PARM::pcszCopyright  = "COPYRIGHT";
  52. PCSZ CL_PARM::pcszId         = "PROGRAM_ID";
  53. PCSZ CL_PARM::pcszName       = "PROGRAM_NAME";
  54. PCSZ CL_PARM::pcszRegister   = "REGISTER";
  55.  
  56.  
  57. //----------------------------------------------------------------------------
  58. //   Description:    Default constructor
  59. //    Parameters:
  60. //       Returns:    
  61. //----------------------------------------------------------------------------
  62. FN_M CL_PARM::CL_PARM()
  63. {
  64.     CL_PARM::Initialize(CL_INIT_CLASS);
  65. }
  66.  
  67.  
  68. //----------------------------------------------------------------------------
  69. //   Description:    Copy constructor
  70. //    Parameters:    rccl_parm        Reference to object to copy.
  71. //       Returns:    
  72. //----------------------------------------------------------------------------
  73. FN_M CL_PARM::CL_PARM(RCCL_PARM rccl_parm)
  74. {
  75.     CL_PARM::Initialize(CL_INIT_CLASS);
  76.     *this = rccl_parm;
  77. }
  78.  
  79.  
  80. //----------------------------------------------------------------------------
  81. //   Description:    Destructor
  82. //    Parameters:
  83. //       Returns:    
  84. //----------------------------------------------------------------------------
  85. FN_M CL_PARM::~CL_PARM()
  86. {
  87.     CL_PARM::Destroy(FALSE);
  88. }
  89.  
  90.  
  91. //----------------------------------------------------------------------------
  92. //   Description:    Destroy object. Free any resources used by object.
  93. //                          Normally called by destructor.
  94. //                        Should allow multiple calls from various classes.
  95. //    Parameters:    fDestroyAll        Destroy parents also?
  96. //                                            Default is TRUE.
  97. //       Returns:    TRUE if successful.
  98. //----------------------------------------------------------------------------
  99. BOOL FN_M CL_PARM::Destroy(BOOL fDestroyAll)
  100. {
  101.     strName.Destroy();
  102.     strVal.Destroy();
  103.     CL_PARM::Initialize(CL_INIT_CLASS_VARS);
  104.     if (fDestroyAll)                            // Destroy parent.
  105.         CL_PARM_PARENT::Destroy(fDestroyAll);                    
  106.     return TRUE;
  107. }
  108.  
  109.  
  110. //----------------------------------------------------------------------------
  111. //   Description:    Get parameter value
  112. //    Parameters:    pcszDft        Default value of string.
  113. //                                        If null, the default is the empty string.
  114. //                                        Default value is NULL.
  115. //                   pcszGarble    If not null, the string is garbled using 
  116. //                                        this key before it is stored.
  117. //                                        Default is NULL.
  118. //       Returns:    TRUE if successful.
  119. //----------------------------------------------------------------------------
  120. BOOL FN_M CL_PARM::Get(PCSZ pcszDft, PCSZ pcszGarble)
  121. {
  122.     if (!strName.IsValid())
  123.         return FALSE;
  124.     if (pcszDft == NULL)
  125.         pcszDft = "";
  126.  
  127.     fValid = FALSE;                            // Clear variables
  128.     fText = TRUE;
  129.     fNumeric = FALSE;
  130.     lVal = lMin;
  131.     strVal.Empty();
  132.  
  133.     PBYTE pb = NULL;
  134.     SIZET cb = 0;
  135.     PCSZ pcszName = pcszGarble ? pcszGarbleName: pcszParmName;
  136.     if (ReadObject((PCSZ)strName, pcszName, &pb, &cb))
  137.         {
  138.         if (pcszGarble)                            // Un garble the string
  139.             {
  140.             PBYTE pbKey = (PBYTE)pcszGarble;
  141.             SIZET cbKey = strlen(pcszGarble) + 1;
  142.             Garble(pb, cb, pbKey, cbKey);
  143.             }
  144.         if (!cb || pb[cb - 1] != '\0')
  145.             return Error("Invalid parameter value.");
  146.         pcszDft = (PCSZ)pb;
  147.         }
  148.     else if (pcszGarble == NULL)            // Check environment variable
  149.         {
  150.         PCSZ pcsz = EnvGet((PCSZ)strName);
  151.         if (pcsz)
  152.             pcszDft = pcsz;
  153.         }
  154.     BOOL fResult = FALSE;
  155.     if (pcszDft)
  156.         fResult = SetValue(pcszDft);
  157.     if (pb)                                        // Free buffer
  158.         MemFree(pb);
  159.     return fResult;
  160. }
  161.  
  162.  
  163. //----------------------------------------------------------------------------
  164. //   Description:    Get parameter value
  165. //    Parameters:    lDft         Default numeric value
  166. //                   pcszGarble        If not null, the string is garbled using 
  167. //                                            this key before it is stored.
  168. //                                            Default is NULL.
  169. //       Returns:    TRUE if successful.
  170. //----------------------------------------------------------------------------
  171. BOOL FN_M CL_PARM::Get(LONG lDft, PCSZ pcszGarble)
  172. {
  173.     CHAR szDft[12];
  174.  
  175.     sprintf(szDft, "%ld", lDft);
  176.     return Get((PCSZ)szDft, pcszGarble);
  177. }
  178.  
  179.  
  180. //----------------------------------------------------------------------------
  181. //   Description:    Get default configuration file parameters
  182. //    Parameters:    
  183. //       Returns:    TRUE if successful.
  184. //----------------------------------------------------------------------------
  185. BOOL FN_M CL_PARM::GetCfg(PBS_CFG pcfg)
  186. {
  187.     CL_PARM cl_parm;
  188.  
  189.     CfgSet(NULL, CFG_CLEAR, pcfg);
  190.     cl_parm.SetName(pcszAccess);
  191.     if (!cl_parm.Get((PCSZ)CFG_ACCESS_DFT,pcszAccess))
  192.         return FALSE;
  193.     CfgSet((PCSZ)cl_parm, CFG_ACCESS, pcfg);
  194.  
  195.     cl_parm.SetName(pcszSerial);
  196.     if (!cl_parm.Get((PCSZ)CFG_SERIAL_NO_DFT,pcszSerial))
  197.         return FALSE;
  198.     CfgSet((PCSZ)cl_parm, CFG_SERIAL_NO, pcfg);
  199.  
  200.     cl_parm.SetName(pcszVersion);
  201.     if (!cl_parm.Get((PCSZ)CFG_VERSION_DFT,pcszVersion))
  202.         return FALSE;
  203.     CfgSet((PCSZ)cl_parm, CFG_VERSION, pcfg);
  204.  
  205.     cl_parm.SetName(pcszCopyright);
  206.     if (!cl_parm.Get((PCSZ)CFG_COPYRIGHT_DFT, pcszCopyright))
  207.         return FALSE;
  208.     CfgSet((PCSZ)cl_parm, CFG_COPYRIGHT, pcfg);
  209.  
  210.     cl_parm.SetName(pcszId);
  211.     if (!cl_parm.Get((PCSZ)CFG_PROGRAM_ID_DFT,pcszId))
  212.         return FALSE;
  213.     CfgSet((PCSZ)cl_parm, CFG_PROGRAM_ID, pcfg);
  214.  
  215.     cl_parm.SetName(pcszName);
  216.     if (!cl_parm.Get((PCSZ)CFG_PROGRAM_NAME_DFT,pcszName))
  217.         return FALSE;
  218.     CfgSet((PCSZ)cl_parm, CFG_PROGRAM_NAME, pcfg);
  219.  
  220.     cl_parm.SetName(pcszRegister);
  221.     if (!cl_parm.Get((PCSZ)CFG_REGISTER_DFT,pcszRegister))
  222.         return FALSE;
  223.     CfgSet((PCSZ)cl_parm, CFG_REGISTER, pcfg);
  224.     return TRUE;
  225. }
  226.  
  227.  
  228. //----------------------------------------------------------------------------
  229. //   Description:    Initialize object. 
  230. //                          Normally called by constructor.
  231. //                        Should allow multiple calls from various classes.
  232. //    Parameters:    sInit        Initialization code. May be one of the following:
  233. //                                        CL_INIT_CLASS            Reset class variables and
  234. //                                                                    and dynamic allocations for
  235. //                                                                    this class only.
  236. //                                        CL_INIT_CLASS_VARS    Reset class variables for
  237. //                                                                    this class only.
  238. //                                        CL_INIT_VARS            Reset class variables for
  239. //                                                                    this class only.
  240. //                                        CL_INIT_ALL                Initialize class and all 
  241. //                                                                    parent class, including
  242. //                                                                    dynamic memory allocation.
  243. //                                    Default is CL_INIT_ALL
  244. //       Returns:    TRUE if successful.
  245. //----------------------------------------------------------------------------
  246. BOOL FN_M CL_PARM::Initialize(SHORT sInit)
  247. {
  248.     if (sInit == CL_INIT_VARS || sInit == CL_INIT_ALL)
  249.         CL_PARM_PARENT::Initialize(sInit);
  250.  
  251.     fValid = FALSE;
  252.     fText = TRUE;
  253.     fNumeric = FALSE;
  254.     lVal = 0;                        
  255.     lMin = MIN_LONG;
  256.     lMax = MAX_LONG;
  257.     strName.Empty();
  258.     strVal.Empty();
  259.     return TRUE;
  260. }
  261.  
  262.  
  263. //----------------------------------------------------------------------------
  264. //   Description:    Check if object is in error state.
  265. //                          IsValid() && IsError() MUST NOT BE DEPENDENT ON ONE ANOTHER.
  266. //    Parameters:
  267. //       Returns:    TRUE if in error state.
  268. //----------------------------------------------------------------------------
  269. BOOL FN_M CL_PARM::IsError() const
  270. {
  271.     return CL_PARM_PARENT::IsError() || strName.IsError() || strVal.IsError();
  272. }
  273.  
  274.  
  275. //----------------------------------------------------------------------------
  276. //   Description:    Check if object is valid
  277. //                          IsValid() && IsError() MUST NOT BE DEPENDENT ON ONE ANOTHER.
  278. //    Parameters:
  279. //       Returns:    TRUE if valid
  280. //----------------------------------------------------------------------------
  281. BOOL FN_M CL_PARM::IsValid() const
  282. {
  283.     return CL_PARM_PARENT::IsValid()
  284.         && fValid
  285.         && strName.IsValid()
  286.         && strVal.IsValid();
  287. }
  288.  
  289.  
  290. //----------------------------------------------------------------------------
  291. //   Description:    Assign minimum and maximum limits for numeric values.
  292. //    Parameters:    lMin        Minimum value.
  293. //                                    Default is MIN_LONG.
  294. //                        lMax        Maximum value.
  295. //                                    Default is MAX_LONG.
  296. //       Returns:    TRUE if successful.
  297. //----------------------------------------------------------------------------
  298. BOOL FN_M CL_PARM::MinMax(LONG lMin, LONG lMax)
  299. {
  300.     if (lMin > lMax)                            // Swap values if needed
  301.         {
  302.         LONG lTemp = lMax;
  303.         lMax = lMin;
  304.         lMin = lTemp;
  305.         }
  306.     CL_PARM::lMin = lMin;                    // Set min/max
  307.     CL_PARM::lMax = lMax;
  308.     if (lVal < lMin)                            // Force numeric value into range
  309.         lVal = lMin;
  310.     if (lVal > lMax)
  311.         lVal = lMax;
  312.     if (!fText && fValid)                    // Re-assign text value of numeric
  313.         {
  314.         strVal("%ld", lVal);
  315.         if (strVal.IsError())
  316.             SetError();
  317.         }
  318.     return !IsError();
  319. }
  320.  
  321.  
  322. //----------------------------------------------------------------------------
  323. //   Description:    Assignment operator
  324. //                          NOTE: Don't copy object into self
  325. //    Parameters:    rccl_parm        Reference to right value.
  326. //       Returns:    Reference to new object.
  327. //----------------------------------------------------------------------------
  328. RCCL_PARM FN_M CL_PARM::operator=(RCCL_PARM rccl_parm)
  329. {
  330.     if (this != &rccl_parm)
  331.         {
  332.         if (rccl_parm.IsError())
  333.             {
  334.             Destroy();
  335.             SetError(rccl_parm.ErrorCode());
  336.             }
  337.         else
  338.             {
  339.             CAST(CL_PARM_PARENT,*this) = CAST(CL_PARM_PARENT,rccl_parm);
  340.           fValid = rccl_parm.fValid;
  341.             fText = rccl_parm.fText;
  342.             fNumeric = rccl_parm.fNumeric;
  343.           lVal = rccl_parm.lVal;
  344.           lMin = rccl_parm.lMin;
  345.           lMax = rccl_parm.lMax;
  346.           strName = rccl_parm.strName;
  347.           strVal = rccl_parm.strVal;
  348.             if (IsError())
  349.                 SetError();
  350.             }
  351.         }
  352.     return (RCCL_PARM)*this;
  353. }
  354.  
  355.  
  356. //----------------------------------------------------------------------------
  357. //   Description:    Set parm using a BYTE value.
  358. //    Parameters:    bVal        Value.
  359. //       Returns:    Reference to parameter
  360. //----------------------------------------------------------------------------
  361. RCCL_PARM FN_M CL_PARM::operator=(BYTE bVal)
  362. {
  363.     SetValue((LONG)bVal);
  364.     return (RCCL_PARM)*this;
  365. }
  366.  
  367.  
  368. //----------------------------------------------------------------------------
  369. //   Description:    Set parm using a CHAR value.
  370. //    Parameters:    chVal        Value.
  371. //       Returns:    Reference to parameter
  372. //----------------------------------------------------------------------------
  373. RCCL_PARM FN_M CL_PARM::operator=(CHAR chVal)
  374. {
  375.     SetValue((CHAR)chVal);
  376.     return (RCCL_PARM)*this;
  377. }
  378.  
  379.  
  380. //----------------------------------------------------------------------------
  381. //   Description:    Set parm using a LONG value.
  382. //    Parameters:    lVal        Value.
  383. //       Returns:    Reference to parameter
  384. //----------------------------------------------------------------------------
  385. RCCL_PARM FN_M CL_PARM::operator=(LONG lVal)
  386. {
  387.     SetValue(lVal);
  388.     return (RCCL_PARM)*this;
  389. }
  390.  
  391.  
  392. //----------------------------------------------------------------------------
  393. //   Description:    Set parm using a PCSZ value.
  394. //    Parameters:    pcsz        Value.
  395. //       Returns:    Reference to parameter
  396. //----------------------------------------------------------------------------
  397. RCCL_PARM FN_M CL_PARM::operator=(PCSZ pcsz)
  398. {
  399.     SetValue(pcsz);
  400.     return (RCCL_PARM)*this;
  401. }
  402.  
  403.  
  404. //----------------------------------------------------------------------------
  405. //   Description:    Set parm using a PSZ value.
  406. //    Parameters:    psz        Value.
  407. //       Returns:    Reference to parameter
  408. //----------------------------------------------------------------------------
  409. RCCL_PARM FN_M CL_PARM::operator=(PSZ psz)
  410. {
  411.     SetValue((PCSZ)psz);
  412.     return (RCCL_PARM)*this;
  413. }
  414.  
  415.  
  416. //----------------------------------------------------------------------------
  417. //   Description:    Set parm using a SHORT value.
  418. //    Parameters:    sVal        Value.
  419. //       Returns:    Reference to parameter
  420. //----------------------------------------------------------------------------
  421. RCCL_PARM FN_M CL_PARM::operator=(SHORT sVal)
  422. {
  423.     SetValue((LONG)sVal);
  424.     return (RCCL_PARM)*this;
  425. }
  426.  
  427.  
  428. //----------------------------------------------------------------------------
  429. //   Description:    Set parm using a ULONG value.
  430. //    Parameters:    ulVal        Value.
  431. //       Returns:    Reference to parameter
  432. //----------------------------------------------------------------------------
  433. RCCL_PARM FN_M CL_PARM::operator=(ULONG ulVal)
  434. {
  435.     SetValue((LONG)ulVal);
  436.     return (RCCL_PARM)*this;
  437. }
  438.  
  439.  
  440. //----------------------------------------------------------------------------
  441. //   Description:    Set parm using a USHORT value.
  442. //    Parameters:    usVal        Value.
  443. //       Returns:    Reference to parameter
  444. //----------------------------------------------------------------------------
  445. RCCL_PARM FN_M CL_PARM::operator=(USHORT usVal)
  446. {
  447.     SetValue((LONG)usVal);
  448.     return (RCCL_PARM)*this;
  449. }
  450.  
  451.  
  452. //----------------------------------------------------------------------------
  453. //   Description:    Cast parm to a BYTE.
  454. //    Parameters:
  455. //       Returns:    Value of cast
  456. //----------------------------------------------------------------------------
  457. FN_M CL_PARM::operator BYTE() const
  458. {
  459.     return (BYTE)lVal;
  460. }
  461.  
  462.  
  463. //----------------------------------------------------------------------------
  464. //   Description:    Cast parm to a CHAR.
  465. //    Parameters:
  466. //       Returns:    Value of cast
  467. //----------------------------------------------------------------------------
  468. FN_M CL_PARM::operator CHAR() const
  469. {
  470.     return (CHAR)lVal;
  471. }
  472.  
  473.  
  474. //----------------------------------------------------------------------------
  475. //   Description:    Cast parm to a LONG.
  476. //    Parameters:
  477. //       Returns:    Value of cast
  478. //----------------------------------------------------------------------------
  479. FN_M CL_PARM::operator LONG() const
  480. {
  481.     return (LONG)lVal;
  482. }
  483.  
  484.  
  485. //----------------------------------------------------------------------------
  486. //   Description:    Cast parm to a PCSZ.
  487. //    Parameters:
  488. //       Returns:    Value of cast
  489. //----------------------------------------------------------------------------
  490. FN_M CL_PARM::operator PCSZ() const
  491. {
  492.     return (PCSZ)strVal;
  493. }
  494.  
  495.  
  496. //----------------------------------------------------------------------------
  497. //   Description:    Cast parm to a PSZ.
  498. //    Parameters:
  499. //       Returns:    Value of cast
  500. //----------------------------------------------------------------------------
  501. FN_M CL_PARM::operator PSZ() const
  502. {
  503.     return (PSZ)strVal;
  504. }
  505.  
  506.  
  507. //----------------------------------------------------------------------------
  508. //   Description:    Cast parm to a RBS_STRING.
  509. //    Parameters:
  510. //       Returns:    Value of cast
  511. //----------------------------------------------------------------------------
  512. FN_M CL_PARM::operator RCL_STRING() const
  513. {
  514.     return (RCL_STRING)strVal;
  515. }
  516.  
  517.  
  518. //----------------------------------------------------------------------------
  519. //   Description:    Cast parm to a SHORT.
  520. //    Parameters:
  521. //       Returns:    Value of cast
  522. //----------------------------------------------------------------------------
  523. FN_M CL_PARM::operator SHORT() const
  524. {
  525.     return (SHORT)lVal;
  526. }
  527.  
  528.  
  529. //----------------------------------------------------------------------------
  530. //   Description:    Cast parm to a ULONG.
  531. //    Parameters:
  532. //       Returns:    Value of cast
  533. //----------------------------------------------------------------------------
  534. FN_M CL_PARM::operator ULONG() const
  535. {
  536.     return (ULONG)lVal;
  537. }
  538.  
  539.  
  540. //----------------------------------------------------------------------------
  541. //   Description:    Cast parm to a USHORT.
  542. //    Parameters:
  543. //       Returns:    Value of cast
  544. //----------------------------------------------------------------------------
  545. FN_M CL_PARM::operator USHORT() const
  546. {
  547.     return (USHORT)lVal;
  548. }
  549.  
  550.  
  551. //----------------------------------------------------------------------------
  552. //   Description:    Retrieve object from persistent storage
  553. //    Parameters:    pcsz        Name of object.
  554. //                        pcszSub    Sub-name of object.
  555. //                                    The first character of the name should be '~'.
  556. //                                    If NULL, no sub name is available.
  557. //                                    Default is NULL
  558. //       Returns:    TRUE if successful.
  559. //----------------------------------------------------------------------------
  560. BOOL FN_M CL_PARM::Retrieve(PCSZ pcsz, PCSZ pcszSub)
  561. {
  562.     NOTUSED(pcsz);
  563.     NOTUSED(pcszSub);
  564.     Invalid("CL_PARM::Retrieve");
  565.     return FALSE;
  566. }
  567.  
  568.  
  569. //----------------------------------------------------------------------------
  570. //   Description:    Store parameter to persistent storage
  571. //    Parameters:    pcszGarble        If not null, the string is garbled using 
  572. //                                            this key before it is stored.
  573. //                                            Default is NULL.
  574. //       Returns:    TRUE if successful.
  575. //----------------------------------------------------------------------------
  576. BOOL FN_M CL_PARM::Set(PCSZ pcszGarble)
  577. {
  578.     if (IsError() || !strName.IsValid())
  579.         return FALSE;
  580.  
  581.     PBYTE pb = (PBYTE)(PSZ)strVal;
  582.     SIZET cb = strVal.Len() + 1;
  583.     PBYTE pbKey;
  584.     SIZET cbKey;
  585.     if (pcszGarble)
  586.         {
  587.         pbKey = (PBYTE)pcszGarble;
  588.         cbKey = strlen(pcszGarble) + 1;
  589.         Garble(pb, cb, pbKey, cbKey);
  590.         }
  591.     PCSZ pcszName = pcszGarble ? pcszGarbleName: pcszParmName;
  592.     if (!WriteObject((PCSZ)strName, pcszName, pb, cb))
  593.         SetError();
  594.     if (pcszGarble)
  595.         Garble(pb, cb, pbKey, cbKey);
  596.     return !IsError();
  597. }
  598.  
  599.  
  600. //----------------------------------------------------------------------------
  601. //   Description:    Set default configuration file parameters
  602. //    Parameters:    
  603. //       Returns:    TRUE if successful.
  604. //----------------------------------------------------------------------------
  605. BOOL FN_M CL_PARM::SetCfg(PBS_CFG pcfg)
  606. {
  607.     CL_PARM cl_parm;
  608.  
  609.     cl_parm.SetName(pcszAccess);
  610.     cl_parm = CfgGet(CFG_ACCESS, pcfg);
  611.     if (!cl_parm.Set(pcszAccess))
  612.         return FALSE;
  613.  
  614.     cl_parm.SetName(pcszSerial);
  615.     cl_parm = CfgGet(CFG_SERIAL_NO, pcfg);
  616.     if (!cl_parm.Set(pcszSerial))
  617.         return FALSE;
  618.  
  619.     cl_parm.SetName(pcszVersion);
  620.     cl_parm = CfgGet(CFG_VERSION, pcfg);
  621.     if (!cl_parm.Set(pcszVersion))
  622.         return FALSE;
  623.  
  624.     cl_parm.SetName(pcszCopyright);
  625.     cl_parm = CfgGet(CFG_COPYRIGHT, pcfg);
  626.     if (!cl_parm.Set(pcszCopyright))
  627.         return FALSE;
  628.  
  629.     cl_parm.SetName(pcszId);
  630.     cl_parm = CfgGet(CFG_PROGRAM_ID, pcfg);
  631.     if (!cl_parm.Set(pcszId))
  632.         return FALSE;
  633.  
  634.     cl_parm.SetName(pcszName);
  635.     cl_parm = CfgGet(CFG_PROGRAM_NAME, pcfg);
  636.     if (!cl_parm.Set(pcszName))
  637.         return FALSE;
  638.  
  639.     cl_parm.SetName(pcszRegister);
  640.     cl_parm = CfgGet(CFG_REGISTER, pcfg);
  641.     if (!cl_parm.Set(pcszRegister))
  642.         return FALSE;
  643.  
  644.     return TRUE;
  645. }
  646.  
  647.  
  648. //----------------------------------------------------------------------------
  649. //   Description:    Set name of parameter
  650. //    Parameters:    pcszName        Name of parameter in a printf() style format
  651. //                                        strings.
  652. //                                        Use '%%' to include a percent sign.
  653. //       Returns:    TRUE if successful.
  654. //----------------------------------------------------------------------------
  655. BOOL FN_MV CL_PARM::SetName(PCSZ pcszName,...)
  656. {
  657.     va_list marker;
  658.     va_start(marker,pcszName);
  659.     strName.Create(0, pcszName, marker);
  660.     va_end(marker);
  661.     strName.Upper();
  662.     if (strName.IsError())
  663.         SetError();
  664.     return !IsError();
  665. }
  666.  
  667.  
  668. //----------------------------------------------------------------------------
  669. //   Description:    Set long value of object.
  670. //    Parameters:    l    New value of object.
  671. //       Returns:    TRUE if successful.
  672. //----------------------------------------------------------------------------
  673. BOOL FN_M CL_PARM::SetValue(LONG l)
  674. {
  675.     fValid = TRUE;
  676.     fText = FALSE;
  677.     fNumeric = TRUE;
  678.     lVal = l;
  679.     strVal.Empty();
  680.     return MinMax(lMin, lMax);                // Call min/max to force into range
  681. }
  682.  
  683.  
  684. //----------------------------------------------------------------------------
  685. //   Description:    Set string value of object.
  686. //    Parameters:    pcsz        New value for object.
  687. //       Returns:    TRUE if successful.
  688. //----------------------------------------------------------------------------
  689. BOOL FN_M CL_PARM::SetValue(PCSZ pcsz)
  690. {
  691.     fValid = TRUE;                                // Clear variables
  692.     fText = TRUE;
  693.     strVal = pcsz;
  694.     if (strVal.IsError())
  695.         return SetError();
  696.     if (!strVal.ValidLong(&lVal))            // Try to extract numeric value
  697.         {
  698.         fNumeric = FALSE;
  699.         lVal = lMin;
  700.         }
  701.     else
  702.         fNumeric = TRUE;
  703.     return MinMax(lMin, lMax);                // Call min/max to force into range
  704. }
  705.  
  706.  
  707. //----------------------------------------------------------------------------
  708. //   Description:    Store object to persistent storage
  709. //    Parameters:    pcsz        Name of object.
  710. //                        pcszSub    Sub-name of object.
  711. //                                    The first character of the name should be '~'.
  712. //                                    If NULL, no sub name is available.
  713. //                                    Default is NULL
  714. //       Returns:    TRUE if successful.
  715. //----------------------------------------------------------------------------
  716. BOOL FN_M CL_PARM::Store(PCSZ pcsz, PCSZ pcszSub)
  717. {
  718.     NOTUSED(pcsz);
  719.     NOTUSED(pcszSub);
  720.     Invalid("CL_PARM::Store");
  721.     return FALSE;
  722. }
  723.  
  724.  
  725. //----------------------------------------------------------------------------
  726. //   Description:    Print object value to debugging output.
  727. //    Parameters:    pccl_parm        Pointer to dynamic object. 
  728. //                                    If NULL, static data elements are printed.
  729. //                                    Default is NULL.
  730. //                        pcsz        Name of object.
  731. //                                    If NULL, no name is displayed.
  732. //                                    Default is NULL.
  733. //                        cLevel    Display level. 
  734. //                                    Default is zero.
  735. //       Returns:
  736. //----------------------------------------------------------------------------
  737. #if COMPILE_DEBUG
  738. VOID FN_M CL_PARM::Print(PCCL_PARM pccl_parm, PCSZ pcsz, SIZET cLevel)
  739. {
  740. #if COMPILE_TEST
  741.     OutputL(cLevel, "CL_PARM%s%s", (pcsz?"::":""), (pcsz?pcsz:""));
  742.     cLevel++;
  743.     if (pccl_parm)
  744.         {
  745.         Output(" <%p>\n", pccl_parm);
  746.         if(!pccl_parm->IsError())
  747.             {
  748.             OutputL(cLevel, "fValid = %d\n", pccl_parm->fValid);
  749.             OutputL(cLevel, "strName = %s\n", (PCSZ)pccl_parm->strName);
  750.             OutputL(cLevel, "strVal = %s\n", (PCSZ)pccl_parm->strVal);
  751.             OutputL(cLevel, "fText = %d\n", pccl_parm->fText);
  752.             OutputL(cLevel, "lVal = %ld\n", pccl_parm->lVal);
  753.             OutputL(cLevel, "lMin = %ld\n", pccl_parm->lMin);
  754.             OutputL(cLevel, "lMax = %ld\n", pccl_parm->lMax);
  755.             }
  756.         }
  757.     else
  758.         Output(" <NULL>\n");
  759.     CL_PARM_PARENT::Print((CL_PARM_PARENT _FAR_ *)pccl_parm, pcsz, cLevel);
  760.     return ;
  761. #else
  762.     NOTUSED(cLevel);
  763.     NOTUSED(pccl_parm);
  764.     NOTUSED(pcsz);
  765.     return ;
  766. #endif
  767. }
  768. #endif
  769.  
  770.  
  771. //----------------------------------------------------------------------------
  772. //   Description:    Run standard test suite on object.
  773. //    Parameters:    sTest        Test to run.
  774. //                                    If 0, run default tests.
  775. //                                    Default is 0.
  776. //       Returns:    TRUE if successful.
  777. //----------------------------------------------------------------------------
  778. #if COMPILE_DEBUG
  779. BOOL FN_M CL_PARM::Test(SHORT sTest)
  780. {
  781. #if COMPILE_TEST
  782.     if (sTest == 1)                            // Test 1 is always a test of storage
  783.         {
  784.         CL_PARM cl_parm;
  785.         cl_parm.Store("CL_PARM");
  786.         cl_parm.Retrieve("CL_PARM");
  787.         CL_PARM::Print(&cl_parm);
  788.         }
  789.  
  790.     NOTUSED(sTest);
  791.  
  792.     CL_PARM parm;
  793.  
  794.     parm.SetName("%s is the Name", "THIS");
  795.     Print(&parm);
  796.  
  797.     parm = (SHORT)5;
  798.     Print(&parm);
  799.  
  800.     SHORT s = parm;
  801.     Output("s = %hd\n", s);
  802.  
  803.     parm = "5567";
  804.     Print(&parm);
  805.  
  806.     parm.MinMax(1, 10);
  807.     Print(&parm);
  808.  
  809.     parm = "This is it.";
  810.     Print(&parm);
  811.  
  812.     parm.Get("Default string");
  813.     Print(&parm);
  814.  
  815.     parm.Set();
  816.     Print(&parm);
  817.  
  818.     parm = NULL;
  819.     parm.Get("New default string");
  820.     Print(&parm);
  821.  
  822.     parm.SetName("ENV_VAR");
  823.     parm = "This is the string value to store.";
  824.     Print(&parm);
  825.     parm.Set("GARBLED NAME");
  826.  
  827.     parm.Destroy();
  828.     parm.SetName("ENV_VAR");
  829.     parm.Get((PSZ)NULL, "GARBLED NAME");
  830.     Print(&parm);
  831.  
  832.     return TRUE;
  833. #else
  834.     NOTUSED(sTest);
  835.     return TRUE;
  836. #endif
  837. }
  838. #endif
  839. //----------------------------------------------------------------------------
  840. //------------------------------- End of File --------------------------------
  841. //----------------------------------------------------------------------------
  842.  
  843.